#include "Rail2.h"
#include <windows.h>
#include <GL/gl.h>

CRail2::CRail2(void) : m_size(this, 1){}
CRail2::CRail2(float size): m_size(this, size){}

void CRail2::doRender()
{
	glPushMatrix();
		drawCube(m_size);
		glTranslatef( -m_size, 0,0);
		drawCube(m_size);
		glTranslatef( -m_size, m_size,0);
		drawCube(m_size);
		glTranslatef( -m_size, m_size,0);
		drawCube(m_size);
		glTranslatef( 4*m_size, 2*-m_size,0);
		drawCube(m_size);
		glTranslatef( m_size,m_size, 0);
		drawCube(m_size);
		glTranslatef( m_size,m_size, 0);
		drawCube(m_size);
	glPopMatrix();
}

void CRail2::drawCube(float size)
{
	glPushMatrix();
	glTranslatef(-size/2, -size/2, -size/2);
	glBegin(GL_QUADS);
		
		glNormal3f(0, 0, 1);
		glVertex3f(0, 0, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, size, 0);
		glVertex3f(0, size, 0);
		
		//ok
		glNormal3f(1, 0, 0);
		glVertex3f(size, size, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, 0, size);
		glVertex3f(size, size, size);
		
		//ok
		glNormal3f(-1, 0, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(0, size, 0);
		glVertex3f(0, size, size);
		glVertex3f(0, 0, size);
		
		glNormal3f(0, 0, -1);
		glVertex3f(0, size, size);
		glVertex3f(0, 0, size);
		glVertex3f(size, 0, size);
		glVertex3f(size, size, size);
		
		//ok
		glNormal3f(0, 1, 0);
		glVertex3f(0, size, size);
		glVertex3f(size, size, size);
		glVertex3f(size, size, 0);
		glVertex3f(0, size, 0);

		//ok
		glNormal3f(0, -1, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, 0, size);
		glVertex3f(0, 0, size);
			
	glEnd();
	glPopMatrix();
}
